// app.js
const http = require('./request/config/http.js')
const api = require('./request/config/api.js')

App({
  onLaunch(options) {
    console.info(options);
    let {
      scene
    } = options.query
    if (options.scene == 1047 && scene) {
      scene = decodeURIComponent(scene)
      let query = this.globalData.getQueryVariable(scene)
      this.globalData.from_uid = query.from_uid
      console.info('分享人ID：', query.from_uid)
    }
    // 请求配置
    wx.http = http
    wx.api = api
    wx.onAppRoute((res) => {
      let pathArr = ['pages/index/index', 'pages/login/index']
      let token = wx.getStorageSync('token')
      if (!token && !pathArr.includes(res.path)) {
      
      }
    })
  },
  // 全局变量
  globalData: {
    from_uid: null,
    // URL 转 JSON
    getQueryVariable(scene) {
      if (!scene) return false
      var vars = scene.split("&");
      let query = {}
      vars.forEach(v => {
        let pair = v.split("=")
        query[pair[0]] = pair[1]
      })
      return query
    }
  },
})